Imports System.IO

Public Class FrmInbox

    Private Sub CmdDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdDownload.Click
        Dim myMail As New angMail

        With myMail
            Debug.WriteLine(.Folder)

            .POPServer = "pop.gmail.com"
            .UserName = "bredrick.sa@gmail.com"
            .PassWord = "spootinick31"
            .Port = 995

            '.POPServer = "pop.anguloinc.com.br"
            '.UserName = "ricardo@anguloinc.com.br"
            '.PassWord = "spootinick3112"
            '.Port = 110

            '.POPServer = "pop.terra.com.br"
            '.UserName = "ricardo_angulo@terra.com.br"
            '.PassWord = "r1s2a3"
            '.Port = 110

            .ConnectSSL()

            '.Connect()

            .SalvarAnexos()
        End With
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strm As Object = CreateObject("ADODB.Stream")
        Dim myMail As Object = CreateObject("CDO.Message")
        strm = myMail.GetStream()
        strm.Type = ADODB.StreamTypeEnum.adTypeText
        strm.LoadFromFile("c:\email.eml")

        strm.Flush()
        Dim attach As Object '= CreateObject("CDO.IBodyPart") 'IBodyPart
        For Each attach In myMail.Attachments
            'MsgBox(attach.FileName)
            attach.SaveToFile("C:\" & attach.FileName)
        Next
    End Sub

    Private Sub CmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdClose.Click
        While True
            For Each sFile As String In Directory.GetFiles(strAppPath & "\mails\", "*.eml")
                Try
                    Dim fs As FileStream = File.Open(sFile, FileMode.Open, FileAccess.ReadWrite)
                    Dim reader As New angEMLReader(fs)
                    fs.Close()


                    Debug.WriteLine(reader.CC)
                    Debug.WriteLine(reader.From)
                    Debug.WriteLine(reader.Subject)
                    Debug.WriteLine(reader.To)
                    Debug.WriteLine(reader.HTMLBody)
                    Debug.WriteLine(reader.Body)
                    Debug.WriteLine(reader.Content_Type)
                    Debug.WriteLine(reader.Content_Transfer_Encoding)
                    Debug.WriteLine(reader.Mime_Version)
                    Debug.WriteLine(reader.Received)
                    Debug.WriteLine(reader.Return_Path)
                    Debug.WriteLine(reader.UnsupportedHeaders)

                    ' .... Process EML file here

                    'File.Delete(sFile)
                Catch err As System.IO.IOException
                    Debug.WriteLine("File " & sFile & " is currently in use.")
                End Try
            Next
        End While

    End Sub
End Class